<template>
<nav class="navbar navbar-expand-lg bg-body-tertiary">
  <div class="container">
    <RouterLink class="navbar-brand" :to="{name: 'home'}">King of Bots</RouterLink>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <RouterLink :class="route_name === 'pk_index' ? 'nav-link active' : 'nav-link'" aria-current="page" :to="{name:'pk_choice'}">对战</RouterLink>
        </li>
        <li class="nav-item">
          <RouterLink :class="route_name === 'record_index' ? 'nav-link active' : 'nav-link'" :to="{name: 'record_index'}">对局列表</RouterLink>
        </li>
        <li class="nav-item">
          <RouterLink :class="route_name === 'ranklist_index'? 'nav-link active' : 'nav-link'" :to="{name: 'ranklist_index'}">排行榜</RouterLink>
        </li>
      </ul>
      <ul class="navbar-nav" v-if="$store.state.user.is_login">
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" @click="clickUser" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                {{ $store.state.user.username }}
          </a>
          <ul class="dropdown-menu">
            <li>
              <RouterLink class="dropdown-item" :to="{name: 'user_bot_index'}">我的Bot</RouterLink>
            </li>
            <li><hr class="dropdown-divider"></li>
            <li>
              <a class="dropdown-item" href="#" @click="logout">退出</a>
            </li>
          </ul>
        </li>
      </ul>
      <ul class="navbar-nav" v-else>
        <li class="nav-item ">
          <RouterLink class="nav-link " :to = "{name: 'user_account_login'}" @click="clickUser" role="button" >
                登录
          </RouterLink>
        </li>
        <li class="nav-item">
          <RouterLink class="nav-link" :to = "{name: 'user_account_register'}" role="button" >
                注册
          </RouterLink>
        </li>
      </ul>
    </div>
  </div>
</nav>
</template>

<script>
import { computed, ref } from 'vue';
import { useRoute } from 'vue-router';
import { useStore } from 'vuex';
export default{

    setup(){
        const store = useStore();
        let isClickUser = ref("");
        isClickUser.value = false;
        const route = useRoute();
        let route_name = computed(()=>route.name);
        const logout = () =>{
          store.dispatch("logout");
        }
        let clickUser = () => {
            isClickUser = true;
        }
        return{
            logout,
            route_name,
            clickUser,
        }
    }

}
</script>

<style scoped>
</style>